<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Agent as AgentModel;

class AgentController extends Controller
{
    /**
     * 聊天经纪人获取
     * author::YangXinPeng
     * @param Request $request
     * @return mixed
     */
     public function getAgentInfo(Request $request)
     {
         $id = $request->get('id');
         $data = AgentModel::where('id',$id)->first()->toArray();
         return $this->success('成功',$data);
     }

    /**
     * 用户端首页经纪人列表
     * author：william
     * @return mixed
     */
    public function agentList()
    {
        $info = AgentModel::select('id','avatar','nick_name','company')->paginate(10);
        $info && $info = $info ->toArray();
        if (empty($info)){
            return $this->fail('没有数据','');
        }
        return $this->success('成功',$info);
    }
    /**
     * 经纪人详情
     * author::william
     * @param Request $request
     * @return void
     */
    public function agentDesc(Request $request)
    {
        $id = $request->get('id');
        if (empty($id) || !is_numeric($id)){
            return $this->fail('参数错误');
        }
        $info = AgentModel::find($id);
        if(!empty($info)){
            $info && $info = $info ->toArray();
            return $this->success('成功',$info);
        }
        return $this->fail('经纪人不存在');
    }


}
